import React,{ Component } from "react";

class ChildComponent extends Component{
  constructor(props){
    super(props)
    this.handleClick = this.handleClick.bind(this)
  }

  handleClick(){
    // 调用父组件传递过来的方法并传递数据
    this.props.sendMessage('hello from child')
  }

  render (){
    return (
      <div>
        <h2>Child子组件</h2>
        <p>{this.props.parentMessage}</p>
        <button onClick = {this.handleClick}>发消息到父组件</button>
      </div>
    )
  }
}

export default ChildComponent